package com.rtos.model.fileSystem;
import com.rtos.model.disk.Disk;

import javax.swing.*;
import java.util.ArrayList;

/**
 * @Author: Redi
 * @Date: 2021/10/11 10:23
 * @Description:
 */
public class FileUtilTest {

    public static void main(String args[]) throws Exception {
        FAT fat = new FAT(new Disk());
        FileUtil fileUtil = FileUtil.getInstance();
        String dirOnePath = "d1";
        String fileOnePath = "f1";
        String contextOne = "f1's content";
        fileUtil.makeDirectory(dirOnePath);
        fileUtil.createFile(fileOnePath,contextOne);
        ArrayList<String> arrayList = fileUtil.getDirectorys("root");
        checkArrayList(arrayList,"root");
        System.out.println("content:"+fileUtil.getFileContent(fileOnePath));
        System.out.println("--------create f2 and d2------");
        String dirTwoPath = "d1/d2/";
        String fileTwoPath = "d1/f2";
        String contextTwo = "f2's content";
        fileUtil.makeDirectory(dirTwoPath);
        fileUtil.createFile(fileTwoPath,contextTwo);
        arrayList = fileUtil.getDirectorys("d1");
        checkArrayList(arrayList,"d1");
        System.out.println("content:"+fileUtil.getFileContent(fileTwoPath));
        /*
        root-----------
                d1-----
                    d2-
                    f2-
                f1-----
        */
        System.out.println("----------test copy---------");
        //test delete
//        fileUtil.deleteFile("d1/f2");
//        arrayList = fileUtil.getDirectorys("d1");
//        checkArrayList(arrayList);
        //test copy
        fileUtil.copyFile(fileTwoPath,dirTwoPath+"f2c");
        arrayList = fileUtil.getDirectorys("d1/d2");
        checkArrayList(arrayList,"d1/d2");
        System.out.println("----------test getAllFile---------");
//        ArrayList fileListArray = new ArrayList();
//        fileUtil.getAllFile("d1/d2",fileListArray);
//        checkArrayList(fileListArray,"d1/d2");
        /*
        root-------------------
                d1-------------
                    d2---------
                       f2c.txt-
                    f2.txt-----
                f1.txt---------
        */
        System.out.println("----------test delete all---------");
        String dirThreePath = "d1/d2/d3";
        fileUtil.makeDirectory(dirThreePath);
        arrayList = fileUtil.getDirectorys("d1/d2");
        checkArrayList(arrayList,"d1/d2/d3");
        fileUtil.deleteAll("d1/d2/d3");

        arrayList = fileUtil.getDirectorys("d1/d2");
        checkArrayList(arrayList,"d1/d2");

        System.out.println("----------test getFileBlock---------");
        ArrayList<Integer> blockList = fileUtil.getFileBlock("f1.txt");
        checkArrayList(blockList,"root");

    }

    private static void checkArrayList(ArrayList arrayList,String path){
        System.out.println("<<<<<<<<<<<<<checkArrayList<<< start <<<<<<<");
        System.out.println("now we are in the path:"+path);
        System.out.println("arrayList.length:"+arrayList.size());
        for (Object o : arrayList){
            System.out.println(o);
        }
        System.out.println(">>>>>>>>>>>>>checkArrayList>>>>> end >>>>>");
    }
}
